//
//  LLBaseTableViewController.swift
//  WeiBoShiBing
//
//  Created by Bingo on 15/10/27.
//  Copyright © 2015年 Bingo. All rights reserved.
//

import UIKit

class LLBaseTableViewController: UITableViewController {

    let userLogin = LLUserAccount.userLogin()
    
    override func loadView() {
        
        userLogin ? super.loadView() : setupVistorView()
        
       
    }
    
    deinit {
    
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    
    func setupVistorView(){
        let vistorView = LLVistorView()
        view = vistorView
        vistorView.vistorViewDelegate = self
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewRegistClick")
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewLoginClick")
        
        
        
        
        
        if self is LLHomeViewController{
            vistorView.startRotationAnimation()
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "DidEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "DidBecomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
            
        }else if self is LLMessageViewController{
            vistorView.setupInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is LLDiscoverViewController{
            vistorView.setupInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is LLProfileViewController{
            vistorView.setupInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
    
       
    }
    
    
    func DidEnterBackground(){
        //暂停动画
        (view as! LLVistorView).pauseAnimation()
    }
    func DidBecomeActive(){
        //继续动画
        (view as! LLVistorView).resumAnimation()
    }
}

extension LLBaseTableViewController: LLVistorViewDelegate{

    func vistorViewLoginClick() {
        let controller = LLOauthViewController()
        
        presentViewController(UINavigationController(rootViewController: controller), animated: true, completion: nil)
    }
    
    func vistorViewRegistClick() {
        print("vistorViewRegistClick")
    }

}